import logging
import logging.handlers

LOG_FILE = 'logging.out'
logging.basicConfig(
    filename=LOG_FILE,
    level=logging.DEBUG
)

logging.debug('This message should go to the log file')

logger = logging.getLogger('module1')

logger.debug('This message should go to the log file')


# logger = logging.getLogger('module2')
#
# logger.debug('This message should go to the log file')
#
# handler = logging.handlers.RotatingFileHandler(
#     LOG_FILE,
#     maxBytes=20,  # 文件大小，超过则生成备份文件
#     backupCount=5  # 备份文件个数
# )
#
# logger.addHandler(handler)
#
# for i in range(20):
#     logger.debug('i = %d' %i)
#
# LEVELS = {
#     'debug': logging.DEBUG,
#     'info': logging.INFO,
#     'warning': logging.WARNING,
#     'error': logging.ERROR,
#     'critical': logging.CRITICAL
# }

logging.debug('This is a debug message')
logging.info('This is an info message')
logging.warning('This is a warning message')
logging.error('This is an error message')
logging.critical('This is a critical message')
